﻿﻿@{
 ViewBag.Title = "Creating a ASP MVC CRUD application";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Creating a ASP MVC CRUD application</h2>
<p>A few years ago, creating a web application with create, read, update and delete (CRUD) functionality with traditional ASP or ASP.NET web forms could become cumbersome. In traditional ASP, developers were left with mixing presentational HTML markup with server-side Visual Basic script, which made creation and maintenance of applications difficult.</p>
<p>When ASP.NET web forms debuted, it shifted the paradigm where developers could at least separate presentational HTML markup from server-side business logic with their preferred object-oriented language (Visual Basic or C#.NET). However, web forms came with out of the box web controls that cornered developers into data controls which often felt bloated and made HTML output rendered by the application server (Internet Information Services) hard to debug.</p>
<p>With the radical shift in development with ASP MVC developers can create web applications like CRUD relatively easy and separate behaviors of concern. Developers have complete control over HTML markup, and the ability to separate classes based on their intended behaviors.</p>
<p>In the following tutorial, we’ll see how we can create a simple applicant system with ASP MVC. We’ll explore how we can either use the existing HTML markup scaffolding Microsoft provides, or create our own. We’ll see a glimpse of the new database access framework known as entity framework and how it can alleviate some of the common mistakes developers using in-line structured query language (SQL) make. We’ll understand how Razor web page views communicate via implicit GET and explicit POST commands. Lastly, we’ll start to see how ASP MVC delivers separation of concerns throughout an application. </p>
<p>If you would like to create an application such as this one, please do follow along in this step-by-step tutorial.</p>
<table cellspacing="0" class="articles" summary="project files">
<tr>
<td colspan="2" class="header">Download Project Files </td>
</tr>
<tr>
<td colspan="2" class="caption"><a href="https://aspmvccrudsystem.codeplex.com/releases/view/616717" target="_blank">Source Files</a></td>
</tr>
</table>
<h3>Prerequisites</h3>
<p>Before beginning we need to make sure we have the following software installed and operational:</p>
<ol>
<li>Microsoft .NET framework or higher</li>
<li> ASP MVC 4 or higher</li>
<li>Microsoft Visual Studio
<li>Microsoft SQL Server Management Studio
<li>Make sure to install the local database service and management studio product</li>
</ol>
<p>Once you have downloaded and installed these applications, open Visual Studio by following these steps:</p>
<ol>
<li>From the desktop, left click Start button</li>
<li>In the search field, type visual studio</li>
<li>Left click to select Visual Studio</li>
</ol>
<p align="center"><img src="@Url.Content("~/content/aspmvccrud/images/start_menu_vs13.jpg")" alt="Start Menu VS 13" width="236" height="429" /></p>
<h3>Creating the project</h3>
<p>From Visual Studio, follow these steps:</p>
<ol>
<li>From the main menu, choose File : New : Project</li>
</ol>
<p align="center"><a href="@Url.Content("~/content/aspmvccrud/images/file-new-project.jpg")" data-lightbox="File New Project"><img src="@Url.Content("~/content/aspmvccrud/images/thumbs/file-new-project.jpg")" alt="File New Project" width="300" height="36" /></a></p>
<ol start="2">
<li>
In the New Project window:
<ol type="a">
<li>From the left pane, leave Visual C# as selected</li>
<li>From the top combo box, choose .NET Framework 4.5.1</li>
<li>From the main window, choose ASP.NET Web Application</li>
</ol>
</li>
</ol>
<p align="center"><a href="@Url.Content("~/content/aspmvccrud/images/select_project_1.jpg")" data-lightbox="Select Project 1"><img src="@Url.Content("~/content/aspmvccrud/images/thumbs/select_project_1.jpg")" alt="Select New Project 1" width="300" height="95" /></a></p>
<ol start="3">
<li>
Next, while in the New Project window, at the bottom:
<ol type="a">
<li>In the name field, type Applicant</li>
<li>In the location field, choose root of C:\</li>
<li>In the solution field, should be auto filled with the same name as the name field (1.)</li>
</ol>
</li>
</ol>
<p align="center"><a href="@Url.Content("~/content/aspmvccrud/images/select_project_2.jpg")" data-lightbox="Select Project 2"><img src="@Url.Content("~/content/aspmvccrud/images/thumbs/select_project_2.jpg")" alt="Select New Project 2" width="300" height="37" /></a></p>
<ol start="4">
<li>
Lastly, while in the New Project window, at the bottom right:
<ol type="a">
<li>In the check box for Create directory for solution, leave checked</li>
<li>In the check box for Add to Source Control, leave unchecked</li>
<li>Once finished, click OK</li>
</ol>
</li>
</ol>
<p align="center"><img src="@Url.Content("~/content/aspmvccrud/images/select_project_3.jpg")" alt="Select New Project 3" width="270" height="137" /></p>
<p>Note: Regarding source control, once we have this project finished, pushing the files into a source control repository such as Team Foundation Server (TFS), Subversion, GitHub or CodePlex should be a straightforward task.</p>
<p>In the next window, choose (1) MVC and click (2) OK:</p>
<p align="center"><a href="@Url.Content("~/content/aspmvccrud/images/select_project_4.jpg")" data-lightbox="Select Project 4"><img src="@Url.Content("~/content/aspmvccrud/images/thumbs/select_project_4.jpg")" alt="Select New Project 4" width="300" height="232" /></a></p>
<p>Once Visual Studio has completed creating the project, we should see from the right side in solution explorer we have a functional web application created with the appropriate folder structure needed for MVC. Go ahead and press F5 on the keyboard to ensure the project builds and launches a web page as shown below:</p>
<p align="center"><img src="@Url.Content("~/content/aspmvccrud/images/default_website.jpg")" alt="Default Website" width="300" height="284" /></p>
<h3>Entity framework with MVC applications</h3>
<p>In the latest versions of the .NET framework, Microsoft has provided a new and more robust approach to data access with ASP MVC applications called entity framework. Entity framework aims to solve some of the common problems associated to data access retrieval and submission from ASP  MVC application including but not limited to:</p>
<ol>
<li>Performance of complex queries: if your application is using complex stored procedures with complex business logic, it may be a worthwhile exercise to determine if using entity framework can speed up the query operation and make the overall query structure easier to write and understand.</li>
<li>Native support of database operations: much like Active Data Objects (ADO), entity framework has native methods to perform common database operations such as selecting, filtering, sorting, adding, updating and deleting data from a database</li>
<li>Native support of parameterized queries: with traditional ASP applications and ADO, we have to explicitly parameterize queries that deal with insertion of data into a database from an application to prevent the use of structured query language (SQL) injection attacks. With entity framework, parameterized queries are natively supported</li>
</ol>
<p>For the purposes of this tutorial, we’ll be using entity framework and a deeper dive using entity framework will be covered later.</p>
<p>We'll continue next with @Html.ActionLink("creating our database", "Index2").</p>
